package jdbc;

import util.DBUtil;

import java.sql.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class MetaData {
    public static void main(String[] args) {
        Connection con= DBUtil.get();
        try {
            DatabaseMetaData metaData = con.getMetaData();
            System.out.println(metaData.getDatabaseProductName());
            System.out.println(metaData.getDatabaseProductVersion());
            System.out.println(metaData.getDriverName());
            System.out.println(metaData.getDriverMajorVersion());
            System.out.println("支持事务："+metaData.supportsTransactions());

            PreparedStatement ps = con.prepareStatement("select * from s_student");
            ResultSet rs = ps.executeQuery();
            ResultSetMetaData rm = rs.getMetaData();
            //获得这个sql的信息
            System.out.println("共有："+rm.getColumnCount()+"列");
            //每一列的详细信息
            for(int i=1;i<=rm.getColumnCount();i++){
                System.out.println("列名："+rm.getColumnLabel(i));
                System.out.println("列类型："+rm.getColumnTypeName(i));
                System.out.println("对应的java类型："+rm.getColumnClassName(i));
            }
            DBUtil.close(con);
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
